package com.cloudsigns.factorymanager2.engineering.activity;

import android.app.Activity;
import android.content.Intent;
import android.graphics.Color;
import android.os.Build;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;

import com.cloudsigns.factorymanager2.R;
import com.cloudsigns.factorymanager2.project.utils.ConstantUtil;

/**
 * 工程 工单管理 分派工单 维修工单
 * Created by tony on 2018/2/2.
 */

public class DispatchEngineeringMaintenanceOrderActivity extends Activity implements View.OnClickListener {
    private ImageView img_back;
    private TextView tv_title;
    private RelativeLayout rl_engineering_name;
    private ImageView img_edit_dispatch_information;
    private TextView edt_dispatching_way_colon, edt_maintenance_perform, edt_reception_statuse_colon;
    private LinearLayout ll_dispatch_content;
    private Button btn_confirm_the_dispatch,btn_confirm_detele;
    private final String TAG = DispatchEngineeringMaintenanceOrderActivity.class.getSimpleName();
    private boolean isClick = false;


    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        this.requestWindowFeature(Window.FEATURE_NO_TITLE);//去掉标题栏
        // 沉浸式状态栏
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
            Window window = getWindow();
            window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS
                    );
            window.getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN

                    | View.SYSTEM_UI_FLAG_LAYOUT_STABLE);
            window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
            window.setStatusBarColor(Color.TRANSPARENT);

        } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
            getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
        }
        setContentView(R.layout.layout_dispatch_engineering_maintenance_order);

        init();
    }

    private void init() {
        img_back = findViewById(R.id.img_back);
        tv_title = findViewById(R.id.tv_title);
        rl_engineering_name=findViewById(R.id.rl_engineering_name);
        img_edit_dispatch_information = findViewById(R.id.img_edit_dispatch_information);
        edt_dispatching_way_colon = findViewById(R.id.edt_dispatching_way_colon);
        edt_maintenance_perform = findViewById(R.id.edt_maintenance_perform);
        edt_reception_statuse_colon = findViewById(R.id.edt_reception_statuse_colon);
        ll_dispatch_content = findViewById(R.id.ll_dispatch_content);
        btn_confirm_the_dispatch = findViewById(R.id.btn_confirm_the_dispatch);
        btn_confirm_detele = findViewById(R.id.btn_confirm_detele);

        tv_title.setText("维修");
        img_back.setOnClickListener(this);
        rl_engineering_name.setOnClickListener(this);
        img_edit_dispatch_information.setOnClickListener(this);
        btn_confirm_the_dispatch.setOnClickListener(this);
        btn_confirm_detele.setOnClickListener(this);

    }

    private void setClickable() {
        if (isClick) {
            btn_confirm_the_dispatch.setBackgroundResource(R.mipmap.btn_long_bg_green);
        } else {
            btn_confirm_the_dispatch.setBackgroundResource(R.mipmap.btn_long_bg_un);
        }
    }

    @Override
    public void onClick(View view) {
        TextView tv;
        Intent mIntent;
        switch (view.getId()) {
            case R.id.img_back:
                finish();
                break;
                // 项目名称/工程名称
            case R.id.rl_engineering_name:
                mIntent=new Intent(DispatchEngineeringMaintenanceOrderActivity.this,EditEngineeringMaintenanceOrderDetailActivity.class);
                startActivity(new Intent(mIntent));
                break;
                // 派工信息
            case R.id.img_edit_dispatch_information:
                mIntent = new Intent(DispatchEngineeringMaintenanceOrderActivity.this, EditDispatchInformationForEngineeringMaintenanceOrderActivity.class);
                startActivityForResult(mIntent, ConstantUtil.START_ACTIVITY_KEY_1);
                break;
                // 删除工单
            case R.id.btn_confirm_detele:
                if (isClick) {
                    ll_dispatch_content.setVisibility(View.GONE);
                    Toast.makeText(DispatchEngineeringMaintenanceOrderActivity.this, "删除成功", Toast.LENGTH_SHORT).show();
                    isClick = false;
                    setClickable();
                }
                break;
                // 派发工单
            case R.id.btn_confirm_the_dispatch:
                if (isClick) {
                    Toast.makeText(DispatchEngineeringMaintenanceOrderActivity.this, "派工成功", Toast.LENGTH_SHORT).show();
                    finish();
                }
                break;


        }
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        switch (requestCode) {
            case ConstantUtil.START_ACTIVITY_KEY_1:
                if (data != null) {
                    ll_dispatch_content.setVisibility(View.VISIBLE);
                    isClick = true;
                    setClickable();
                }

                break;

        }
        super.onActivityResult(requestCode, resultCode, data);
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
    }
}
